package vn.hoasua.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.openweathermap.model.Cities;

import android.content.Context;

public class FileUtil {
	Context context;
	private FileUtil() {
	}
	public static String getStringFromAssets(Context context,String fileName){
		try{
		StringBuilder buf=new StringBuilder();
	    InputStream json=context.getAssets().open(fileName);
	    BufferedReader in= new BufferedReader(new InputStreamReader(json));
	    String str;

	    while ((str=in.readLine()) != null) {
	      buf.append(str);
	    }

	    in.close();
	    return buf.toString();
		}catch(IOException e){
			return "";
		}
	}
	
	public static Cities[] getCitiesFromAssets(Context context){
		String json = FileUtil.getStringFromAssets(context,"cities.json");
		if(json.equals("")) return new Cities[0];
		return Cities.parse(json);
	}
}
